angular.module('wanhang.controllers', [])

    .controller('HomeCtrl', function ($scope) {
    })

    .controller('CategoryCtrl', function ($scope, categories) {
        $scope.categories = categories;
    })

    .controller('ProductListCtrl', function ($scope, products) {
        $scope.products = products.data;
    })

    .controller('ProductDetailCtrl', function ($scope, product) {
        $scope.product = product;
    })

    .controller('NewsListCtrl', function ($scope, news) {
        $scope.news = news.data;
    })

    .controller('NewsDetailCtrl', function ($scope, news) {
        $scope.news = news;
    })

    .controller('ShareCtrl', function ($scope, $ionicScrollDelegate) {
        $scope.share = true;

        $scope.backTop = function(){
            $ionicScrollDelegate.scrollTop();
        };
    })

    .controller('JobListCtrl', function($scope, jobs) {
        $scope.jobs = jobs;
    })

    .controller('JobDetailCtrl', function($scope, job) {
        $scope.job = job;

    })

    .controller('ResumeCtrl', function ($scope, job, Resumes, $state, $ionicModal) {
        $scope.resume = {};
        $scope.job = job;
        $scope.resume.job_id = job.id;

        if(window.localStorage['resume_session'+job.id]) {
            $scope.session = true;
        }

        $scope.pushResume = function () {
            var resume = angular.copy($scope.resume);
            //console.log($scope.resume.job_id);

            console.log(resume);
            Resumes.save(resume, 
                function(res) {
                    console.log(res);
                    $scope.resume = {};
                    $state.go($state.current, {}, {reload: true});
                    window.localStorage['resume_session'+job.id] = true;
                }, 
                function() {
                    console.log("错误")
            });
        };
    });
